package com.cdbkj.cloud.pos;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.cdbkj.cloud.pos.bean.Filed;
import com.cdbkj.cloud.pos.bean.PrintModel;
import com.dawn.cloud.pos.drive.hardware.printer.PosPrinter;
import com.dawn.cloud.pos.drive.hardware.printer.SNBCPosPrinterConfig;
import com.dawn.cloud.pos.drive.sdk.PrintSdk;

import java.util.ArrayList;
import java.util.List;

public class PrinterTest extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.printer_test);

        ((TextView) findViewById(R.id.name)).setText("Printer:");

        findViewById(R.id.open).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSuccess = PosPrinter.getPrinter().openPrinter();
                if (isSuccess) {
                    Toast.makeText(PrinterTest.this, "printer open success",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(PrinterTest.this, "printer open fail",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        findViewById(R.id.state).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        findViewById(R.id.close).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isSuccess = PosPrinter.getPrinter().closePrinter();
                if (isSuccess) {
                    Toast.makeText(PrinterTest.this, "printer close success",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(PrinterTest.this, "printer close fail",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        findViewById(R.id.print_width_58).setOnClickListener(
                new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PosPrinter.getPrinter().setMaxCharCount(
                                SNBCPosPrinterConfig.MAX_CHAR_COUNT_580);
                    }
                });

        findViewById(R.id.print_width_80).setOnClickListener(
                new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PosPrinter.getPrinter().setMaxCharCount(
                                SNBCPosPrinterConfig.MAX_CHAR_COUNT_800);
                    }
                });

        findViewById(R.id.print_text).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                List<PrintModel> list = new ArrayList<>();
                list.add(new PrintModel("流水号","00000000035"));
                list.add(new PrintModel("门诊号","20180705001"));
                list.add(new PrintModel("姓名","张三"));
                list.add(new PrintModel("挂号科室","眼科"));
                list.add(new PrintModel("看诊日期","2018-07-05"));
                list.add(new PrintModel("金额","4.5 元"));

                String receiptType = Filed.RECEIPT_TYPE_PAY_REGISTER;
                String title = "会泽县人民医院";
                String regDate = "2018-07-05 16:12:08";
                String patientId = "11";
                PrintSdk.print(list,receiptType,title,regDate,patientId,"挂号成功，请您准时到相应诊室候诊");
            }
        });


    }
}
